<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增排班申请')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: datetimepicker-js" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-application-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">排班名称：</label>
                <div class="col-sm-8">
                    <input name="arrangeName" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">创建人：</label>
                <div class="col-sm-8">
                    <input name="createPerson" class="form-control" type="text" th:value="${@permission.getPrincipalProperty('userName')}" disabled>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">创建时间：</label>
                <div class="col-sm-8">
                    <input name="createTime" class="form-control" type="text" th:value="${#dates.format(#dates.createNow(), 'yyyy-MM-dd HH:mm:ss')}" disabled />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">紧急程度：</label>
                <div class="col-sm-8">
                    <select name="level" class="form-control m-b" th:with="type=${@dict.getType('tmd_duty_level')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">部门：</label>
                <div class="col-sm-8">
                    <select id="deptId" name="deptId" class="form-control"></select>
                </div>
            </div>
            <table style="margin: 0 auto">
                <tr>
                    <td>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">日期：</label>
                            <div class="col-sm-8">
                                <div class="input-group date" >
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="text" id="dutyDate_1" class="form-control laydate-demo-2" name="dutyDate_1" placeholder="--请选择日期--">
                                </div>
                            </div>
                        </div>
                    </td>
                    <td >
                        <div class="form-group"  style="width: 326px">
                            <label class="col-sm-3 control-label"  style="width: 82px">值班人：</label>
                            <div class="col-sm-8">
                                <select class="form-control dutyPerson" name="dutyPersonId" id="dutyPersonId_1"></select>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">日期：</label>
                            <div class="col-sm-8">
                                <div class="input-group date">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="text" id="dutyDate_2" class="form-control laydate-demo-2" name="dutyDate_2" placeholder="yyyy-MM-dd" disabled>
                                </div>
                            </div>
                        </div>
                    </td>
                    <td >
                        <div class="form-group"  style="width: 326px">
                            <label class="col-sm-3 control-label"  style="width: 82px">值班人：</label>
                            <div class="col-sm-8">
                                <select class="form-control dutyPerson" name="dutyPersonId" id="dutyPersonId_2"></select>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">日期：</label>
                            <div class="col-sm-8">
                                <div class="input-group date">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="text" id="dutyDate_3" class="form-control laydate-demo-2" name="dutyDate_3" placeholder="yyyy-MM-dd" disabled>
                                </div>
                            </div>
                        </div>
                    </td>
                    <td >
                        <div class="form-group"  style="width: 326px">
                            <label class="col-sm-3 control-label"  style="width: 82px">值班人：</label>
                            <div class="col-sm-8">
                                <select class="form-control dutyPerson" name="dutyPersonId" id="dutyPersonId_3"></select>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">日期：</label>
                            <div class="col-sm-8">
                                <div class="input-group date">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="text" id="dutyDate_4" class="form-control laydate-demo-2" name="dutyDate_4" placeholder="yyyy-MM-dd" disabled>
                                </div>
                            </div>
                        </div>
                    </td>
                    <td >
                        <div class="form-group"  style="width: 326px">
                            <label class="col-sm-3 control-label"  style="width: 82px">值班人：</label>
                            <div class="col-sm-8">
                                <select class="form-control dutyPerson" name="dutyPersonId" id="dutyPersonId_4"></select>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">日期：</label>
                            <div class="col-sm-8">
                                <div class="input-group date">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="text" id="dutyDate_5" class="form-control laydate-demo-2" name="dutyDate_5" placeholder="yyyy-MM-dd" disabled>
                                </div>
                            </div>
                        </div>
                    </td>
                    <td >
                        <div class="form-group"  style="width: 326px">
                            <label class="col-sm-3 control-label"  style="width: 82px">值班人：</label>
                            <div class="col-sm-8">
                                <select class="form-control dutyPerson" name="dutyPersonId" id="dutyPersonId_5"></select>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">日期：</label>
                            <div class="col-sm-8">
                                <div class="input-group date">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="text" id="dutyDate_6" class="form-control laydate-demo-2" name="dutyDate_6" placeholder="yyyy-MM-dd" disabled>
                                </div>
                            </div>
                        </div>
                    </td>
                    <td >
                        <div class="form-group"  style="width: 326px">
                            <label class="col-sm-3 control-label"  style="width: 82px">值班人：</label>
                            <div class="col-sm-8">
                                <select class="form-control dutyPerson" name="dutyPersonId" id="dutyPersonId_6"></select>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">日期：</label>
                            <div class="col-sm-8">
                                <div class="input-group date">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="text" id="dutyDate_7" class="form-control laydate-demo-2" name="dutyDate_7" placeholder="yyyy-MM-dd" disabled>
                                </div>
                            </div>
                        </div>
                    </td>
                    <td >
                        <div class="form-group"  style="width: 326px">
                            <label class="col-sm-3 control-label"  style="width: 82px">值班人：</label>
                            <div class="col-sm-8">
                                <select class="form-control dutyPerson" name="dutyPersonId" id="dutyPersonId_7"></select>
                            </div>
                        </div>
                    </td>
                </tr>
            </table>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="notes" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">附件：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="file">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="file" name="file" type="file">
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/application"
        $("#form-application-add").validate({
            rules:{
                deptId:{
                    required: true,
                },
                dutyPersonId:{
                    required: true,
                },
            },
            messages:{
                deptId:{
                    required: "请重新选择部门",
                },
                dutyPersonId:{
                    required: "请选择值班人",
                },
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-application-add').serialize());
            }
        }

        $(".file-upload").fileinput({
            uploadUrl: ctx + 'common/upload',
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })
    </script>
    <script th:inline="javascript">
        /**
         * 选择部门就查询出该部门的所有员工
         */
        $(document).ready(function() {//页面加载时运行此函数 放在最前端
            $.ajax({
                url: ctx + "system/dept/getDeptList",
                type: 'GET',
                success:function (data) {
                    <!--清空下拉框中的缓存-->
                    $("#deptId").empty();
                    <!--避免下拉框的值不变-->
                    $("#deptId").append("<option value=''>请选择部门</option>");
                    <!--使用循环解析后端传来的数据，并用使用js动态拼接html语言-->
                    for (var i = 0; i < data.length; i++){
                        $("#deptId").append("<option value='" + data[i].deptId + "'>" + data[i].deptName + "</option>");
                    }
                }
            });
            $("#deptId").change(function () {//同上面一样
                // alert($("#deptId").val())
                $.ajax({
                    url: ctx + "system/user/getAllUserByDeptId",
                    type: 'GET',
                    data: {
                        //注意：此处传递的值的名字id必须和后端接受的相同，否则接收不到
                        id: $("#deptId").val(),
                    },
                    success:function (data) {
                        $(".dutyPerson").empty();
                        $(".dutyPerson").append("<option value=''>请选择值班人</option>");
                        for (var i = 0; i < data.length; i++){
                            $(".dutyPerson").append("<option value='" + data[i].userId + "'>" + data[i].userName + "</option>");
                        }
                    }
                });
            });
        });

        $("input[name='dutyDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        var dutyDateList=[];

        $(function(){
            <!-- laydate示例 -->
            layui.use('laydate', function(){
                var laydate = layui.laydate;

                laydate.render({
                    elem: '#dutyDate_1',
                    type: 'date',
                    done: function(value, date){
                        var newData=new Date(date.year,date.month-1,date.date);
                        // console.log(value); //得到日期生成的值，如：2017-08-18
                        // console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                        dutyDateList.push(newData)
                        newData.setDate(newData.getDate()+1)
                        dutyDateList.push(newData)
                        laydate.render({
                            elem: '#dutyDate_2',
                            value: newData
                        });
                        newData.setDate(newData.getDate()+1)
                        dutyDateList.push(newData)
                        laydate.render({
                            elem: '#dutyDate_3',
                            value: newData
                        });
                        newData.setDate(newData.getDate()+1)
                        dutyDateList.push(newData)
                        laydate.render({
                            elem: '#dutyDate_4',
                            value: newData
                        });
                        newData.setDate(newData.getDate()+1)
                        dutyDateList.push(newData)
                        laydate.render({
                            elem: '#dutyDate_5',
                            value: newData
                        });
                        newData.setDate(newData.getDate()+1)
                        dutyDateList.push(newData)
                        laydate.render({
                            elem: '#dutyDate_6',
                            value: newData
                        });
                        newData.setDate(newData.getDate()+1)
                        dutyDateList.push(newData)
                        laydate.render({
                            elem: '#dutyDate_7',
                            value: newData
                        });
                    }
                });
            });
        });
        var dutyPerSonList=[];
        var submit=function () {
            $('.dutyPerson').each(function(index, el) {
                console.log($(this))
                // if($(this).prop('checked')){
                //     ids.push($(this).val())
                //     console.log(ids)
                // }
            });
        }

    </script>
</body>
</html>